package com.creating.mict.service.impl;



import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import com.creating.mict.dao.XyjDao;
import com.creating.mict.domain.Patient;
import com.creating.mict.domain.PatientRule;
import com.creating.mict.domain.PatientSetting;
import com.creating.mict.domain.XtyRecord;
import com.creating.mict.domain.XyjRecord;
import com.creating.mict.service.IXyjService;


/**
 * @ClassName: ColumnServiceImpl
 * @Description: 栏目service实现类
 * @author xuelei
 * @date 2012-3-9 下午7:57:34
 * 
 */
public class XyjServiceImpl implements IXyjService {

	@Resource
	private XyjDao xyjDao;
	
	/**
	 * 
	* @Title: queryPatientXyj 
	* @Description: 获取血压计签约患者及其测量结果
	* @param @param fbtime
	* @param @param fetime
	* @param @param fstate
	* @param @param fkeywords
	* @param @return 
	* @return List<XyjRecord>    返回类型 
	* @throws
	 */
	public List<XyjRecord> queryPatientXyj(String loginName, String foffice, String fbtime, String fetime, String fstate, String fkeywords, String ftakeBack) {
		return xyjDao.queryPatientXyj(loginName, foffice, fbtime, fetime, fstate, fkeywords, ftakeBack);
	}
	

	
	/**
	 * 
	* @Title: produceXyjToChart 
	* @Description: 获取血压及心率测量数据变化曲线
	* @param @param hospitalName
	* @param @param fbh
	* @param @param fquery_str
	* @param @param ri
	* @param @param ftitle
	* @param @return 
	* @return String    返回类型 
	* @throws
	 */
	public String produceXyjToChart(String fbtime, String fetime, String fphone1, String fname) {
		List<XyjRecord> list = new ArrayList<XyjRecord> ();
		
		list = xyjDao.produceXyjToChart(fbtime, fetime, fphone1);
		
		//图表xml字符串
		StringBuffer xmlStr = new StringBuffer("");
		xmlStr.append("<chart bgColor='EEEEEE' showValues='0' labelDisplay='Rotate' slantLabels='1' baseFontSize='12' decimalPrecision='1' showNames='1' formatNumberScale='0' caption='" 
				+ fname + "血压及心率测量值变化曲线' baseFont='宋体' useRoundEdges='1' yAxisName='' canvasBorderThickness='1' numberPrefix='' " 
				+ " >");
		
		//x轴
		xmlStr.append("<categories font='宋体' fontSize='12' fontColor='000000'>");
		String value = "";
		XyjRecord xr = new XyjRecord();
		for(int i = 0; i < list.size(); i++) {
			xr = list.get(i);
			if(xr != null) {
				value = xr.getFrdateStr().substring(5, 10);
			} else {
				value = "";
			}
			xmlStr.append("<category name='" + value + "' />"); 
		}
		xmlStr.append("</categories>");
		
		xmlStr.append("<dataset seriesName='收缩压' color='1D8BD1' anchorBorderColor='1D8BD1' anchorBgColor='1D8BD1'>");
		for (int i = 0; i < list.size(); i++) {
			xr = list.get(i);
			if(xr != null) {
				value = xr.getFssy();
				if(value == null || value.equals("null") || value.equals("")) {
					xmlStr.append("<set value='0' />");
				} else {
					xmlStr.append("<set value='" + value + "' />");
				}
			} else {
				xmlStr.append("<set value='0' />");
			}
		}
		xmlStr.append("</dataset>");
		
		xmlStr.append("<dataset seriesName='舒张压' color='F1683C' anchorBorderColor='F1683C' anchorBgColor='F1683C'>");
		for (int i = 0; i < list.size(); i++) {
			xr = list.get(i);
			if(xr != null) {
				value = xr.getFszy();
				if(value == null || value.equals("null") || value.equals("")) {
					xmlStr.append("<set value='0' />");
				} else {
					xmlStr.append("<set value='" + value + "' />");
				}
			} else {
				xmlStr.append("<set value='0' />");
			}
		}
		xmlStr.append("</dataset>");
		
		xmlStr.append("<dataset seriesName='心率' color='2AD62A' anchorBorderColor='2AD62A' anchorBgColor='2AD62A'>");
		for (int i = 0; i < list.size(); i++) {
			xr = list.get(i);
			if(xr != null) {
				value = xr.getFxl();
				if(value == null || value.equals("null") || value.equals("")) {
					xmlStr.append("<set value='0' />");
				} else {
					xmlStr.append("<set value='" + value + "' />");
				}
			} else {
				xmlStr.append("<set value='0' />");
			}
		}
		xmlStr.append("</dataset>");
		
		xmlStr.append("</chart>");
		return "" + xmlStr;
	} 
	
	
	/**
	 * 
	* @Title: signPatientRule 
	* @Description: 保存患者设置
	* @param @param pr
	* @param @return 
	* @return boolean    返回类型 
	* @throws
	 */
	public boolean signPatientRule(PatientRule pr) {
		
		return xyjDao.signPatientRule(pr);
	}
	
	/**
	 * 
	* @Title: saveXyjOfSetting 
	* @Description: 保存血压计设置信息 
	* @param @param fssy_low
	* @param @param fssy_high
	* @param @param fszy_low
	* @param @param fszy_high
	* @param @param fxl_low
	* @param @param fxl_high
	* @param @param fmyc_low
	* @param @param fmyc_high
	* @param @return 
	* @return boolean    返回类型 
	* @throws
	 */
	public boolean saveXyjOfSetting(String fphone, String fssy_low, String fssy_high, String fszy_low, String fszy_high, String fxl_low, String fxl_high, String fmyc_low, String fmyc_high) {
		return xyjDao.saveXyjOfSetting(fphone, fssy_low, fssy_high, fszy_low, fszy_high, fxl_low, fxl_high, fmyc_low, fmyc_high);
	}
	

	/**
	 * 
	* @Title: getPatientSettingInfoByPhone 
	* @Description: 获取患者设置信息 
	* @param @param fphone
	* @param @return 
	* @return PatientSetting    返回类型 
	* @throws
	 */
	public PatientSetting getPatientSettingInfoByPhone(String fphone) { 
		return xyjDao.getPatientSettingInfoByPhone(fphone);
	}
	
	
	
	/**
	 * 
	* @Title: produceXyjToChartByPerson 
	* @Description: 外网查询 获取血压及心率测量数据变化曲线
	* @param @param fphone1
	* @param @param fstate
	* @param @return 
	* @return String    返回类型 
	* @throws
	 */
	public String produceXyjToChartByPerson(String fphone1, String fstate) {
		List<XyjRecord> list = new ArrayList<XyjRecord> ();
		int num = 0;
		if(fstate != null) { 
			num = Integer.parseInt(fstate);
		} else {
			num = 0;
		}
		
		list = xyjDao.produceXyjToChart(fphone1, num);
		
		//图表xml字符串
		StringBuffer xmlStr = new StringBuffer("");
		xmlStr.append("<chart bgColor='EEEEEE' showValues='0' labelDisplay='Rotate' slantLabels='1' baseFontSize='12' decimalPrecision='1' showNames='1' formatNumberScale='0' caption='" 
				+ fphone1 + "血压及心率测量值变化曲线' baseFont='宋体' useRoundEdges='1' yAxisName='' canvasBorderThickness='1' numberPrefix='' " 
				+ " >");
		
		//x轴
		xmlStr.append("<categories font='宋体' fontSize='12' fontColor='000000'>");
		String value = "";
		XyjRecord xr = new XyjRecord();
		for(int i = 0; i < list.size(); i++) {
			xr = list.get(i);
			if(xr != null) {
				value = xr.getFrdateStr().substring(5, 10);
			} else {
				value = "";
			}
			xmlStr.append("<category name='" + value + "' />"); 
		}
		xmlStr.append("</categories>");
		
		xmlStr.append("<dataset seriesName='收缩压' color='1D8BD1' anchorBorderColor='1D8BD1' anchorBgColor='1D8BD1'>");
		for (int i = 0; i < list.size(); i++) {
			xr = list.get(i);
			if(xr != null) {
				value = xr.getFssy();
				if(value == null || value.equals("null") || value.equals("")) {
					xmlStr.append("<set value='0' />");
				} else {
					xmlStr.append("<set value='" + value + "' />");
				}
			} else {
				xmlStr.append("<set value='0' />");
			}
		}
		xmlStr.append("</dataset>");
		
		xmlStr.append("<dataset seriesName='舒张压' color='F1683C' anchorBorderColor='F1683C' anchorBgColor='F1683C'>");
		for (int i = 0; i < list.size(); i++) {
			xr = list.get(i);
			if(xr != null) {
				value = xr.getFszy();
				if(value == null || value.equals("null") || value.equals("")) {
					xmlStr.append("<set value='0' />");
				} else {
					xmlStr.append("<set value='" + value + "' />");
				}
			} else {
				xmlStr.append("<set value='0' />");
			}
		}
		xmlStr.append("</dataset>");
		
		xmlStr.append("<dataset seriesName='心率' color='2AD62A' anchorBorderColor='2AD62A' anchorBgColor='2AD62A'>");
		for (int i = 0; i < list.size(); i++) {
			xr = list.get(i);
			if(xr != null) {
				value = xr.getFxl();
				if(value == null || value.equals("null") || value.equals("")) {
					xmlStr.append("<set value='0' />");
				} else {
					xmlStr.append("<set value='" + value + "' />");
				}
			} else {
				xmlStr.append("<set value='0' />");
			}
		}
		xmlStr.append("</dataset>");
		
		xmlStr.append("</chart>");
		return "" + xmlStr;
	} 
	
	
}
